package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.InStockItemVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/business/inStock/")
public class InStockController {
    @Autowired
    private InStockService inStockService;

    //入库记录的列表
    @GetMapping("/findInStockList")
    public ResponseBean findInStockList(@RequestParam Map<String,Object> queryMap){
        PageVO<InStockVO> inStockList = inStockService.findInStockList(queryMap);
        return ResponseBean.success(inStockList);
    }
    //入库记录的明细
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id, @RequestParam Integer pageNum){
        Map<Object, Object> detail = inStockService.detail(id, pageNum);
        return ResponseBean.success(detail);
    }
    //放入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        inStockService.remove(id);
        return ResponseBean.success();
    }
    //恢复状态
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        inStockService.back(id);
        return ResponseBean.success();
    }
    //删除入库记录
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        inStockService.delete(id);
        return ResponseBean.success();
    }
    //添加入库记录
    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String username = JWTUtils.getUsername(token);
        inStockService.addIntoStock(inStockVO,username);
        return ResponseBean.success();
    }
    //入库记录的审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        inStockService.publish(id);
        return ResponseBean.success();
    }

}
